package com.sxfq.loansupermarket.backsystem.modular.consultInfo.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.modular.consultInfo.dao.EkanyaDao;
import com.sxfq.loansupermarket.backsystem.modular.consultInfo.entity.EkanyaInfo;
import com.sxfq.loansupermarket.backsystem.modular.consultInfo.entity.SearchEkanyaInfo;
import com.sxfq.loansupermarket.backsystem.modular.consultInfo.service.IEkanyaService;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class EkanyaServiceImpl implements IEkanyaService {

    @Autowired
    private EkanyaDao dao;

    @Override
    public List<EkanyaInfo> selectPageListByQueryGetMap(Page<EkanyaInfo> page, SearchEkanyaInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerName())) {
            params.put("customerName", searchInfo.getCustomerName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerPhone())) {
            params.put("customerPhone", searchInfo.getCustomerPhone());
        }

        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getArchiving())) {
            params.put("archiving", searchInfo.getArchiving());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCaseNo())) {
            params.put("caseNo", searchInfo.getCaseNo());
        }

        if (StringUtil.isNotEmpty(searchInfo.getStartGetTime())) {
            params.put("startGetTime", searchInfo.getStartGetTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndGetTime())) {
            params.put("endGetTime", searchInfo.getEndGetTime());
        }

        if (!"请选择".equals(searchInfo.getOneChannel())) {
            if (StringUtil.isNotEmpty(searchInfo.getOneChannel())) {
                params.put("oneChannel", searchInfo.getOneChannel());
            }
        }
        if (StringUtil.isNotEmpty(searchInfo.getOutpatientName())) {
            params.put("outpatientName", searchInfo.getOutpatientName());
        }
        params.put("startIndex", searchInfo.getStartIndex());
        params.put("limitIndex", searchInfo.getLimitIndex());
        return dao.getQueryPage(page, params);
    }

    @Override
    public int getQueryPagesCount(Page<EkanyaInfo> page, SearchEkanyaInfo searchInfo) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", page);
        if (StringUtil.isNotEmpty(searchInfo.getReach())) {
            params.put("reach", searchInfo.getReach());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerName())) {
            params.put("customerName", searchInfo.getCustomerName());
        }
        if (StringUtil.isNotEmpty(searchInfo.getCustomerPhone())) {
            params.put("customerPhone", searchInfo.getCustomerPhone());
        }

        if (StringUtil.isNotEmpty(searchInfo.getStartGetTime())) {
            params.put("startGetTime", searchInfo.getStartGetTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getEndGetTime())) {
            params.put("endGetTime", searchInfo.getEndGetTime());
        }
        if (StringUtil.isNotEmpty(searchInfo.getFieldTc())) {
            params.put("fieldTc", searchInfo.getFieldTc());
        }
        if (StringUtil.isNotEmpty(searchInfo.getDoctor())) {
            params.put("doctor", searchInfo.getDoctor());
        }
        if (!"请选择".equals(searchInfo.getOneChannel())) {
            if (StringUtil.isNotEmpty(searchInfo.getOneChannel())) {
                params.put("oneChannel", searchInfo.getOneChannel());
            }
        }
        return dao.getQueryPagesCount(page, params);
    }
}